<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>登录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/css/public.css" media="all" />
</head>
<body class="loginBody">
<form class="layui-form">
    <div class="login_face"><img src="/images/tota.jpg" class="userAvatar"></div>
    <div class="layui-form-item input-item">
        <label for="userName">用户名</label>
        <input type="text" placeholder="请输入用户名" autocomplete="off" id="userName" name="adminName" class="layui-input" lay-verify="required|adminName">
    </div>
    <div class="layui-form-item input-item">
        <label for="password">密码</label>
        <input type="password" placeholder="请输入密码" autocomplete="off" id="password" name="password" class="layui-input" lay-verify="required|pass">
    </div>
    <div class="layui-form-item">
        <button class="layui-btn layui-block" lay-filter="formDemo" lay-submit>登录</button>
    </div>

</form>
<script type="text/javascript" src="/layui/layui.js"></script>
<script>
    layui.use(['layer', 'form','jquery'], function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

        form.verify({
            adminName: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!/[a-zA-Z]{1}([a-zA-Z0-9]){3,15}$/.test(value)){
                    return '字符或字母4-15位';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '用户名不能全为数字';
                }
            }

            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            ,pass: [
                /^[\S]{5,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });


        //登录按钮
        form.on("submit(formDemo)",function(data){
            var btn =  $(this);
            btn.text("登录中...").attr("disabled","disabled").addClass("layui-disabled");

            $.post("/admin/login",data.field,function (result) {
                btn.text("登录").attr("disabled",false).removeClass("layui-disabled");
                if(result.success){
                    location.href="/admin/index.html";
                }
                layer.msg(result.content);
            },"json")

            return false;
        })

        //表单输入效果
        $(".loginBody .input-item").click(function(e){
            e.stopPropagation();
            $(this).addClass("layui-input-focus").find(".layui-input").focus();
        })
        $(".loginBody .layui-form-item .layui-input").focus(function(){
            $(this).parent().addClass("layui-input-focus");
        })
        $(".loginBody .layui-form-item .layui-input").blur(function(){
            $(this).parent().removeClass("layui-input-focus");
            if($(this).val() != ''){
                $(this).parent().addClass("layui-input-active");
            }else{
                $(this).parent().removeClass("layui-input-active");
            }
        })
    })
</script>
</body>
</html>